



$(".denglu-btn").click(function () {


  // 验证账号密码不能为空
  if ($("[name='username']").val() == '') {
    layer.msg('用户名不能为空', {
      time: 1000
    })
    return false
  }
  if ($("[name='password']").val() == '') {
    layer.msg('密码不能为空', {
      time: 1000
    })
    return false
  }


  // 发送请求  看数据库是否存在该账号
  var loadindex = layer.load(0, {
    shade: [2, 'rgb(161, 157, 157)']
  })
  $.ajax({
    url: './php/denglu.php',
    method: "post",
    data: {
      username: $("[name='username']").val(),
      password: $("[name='password']").val()
    },
    success: function (res) {
      var { meta: { status, msg } } = res
      layer.close(loadindex)
      if (status == 1) {
        setCookie('username', $("[name='username']").val(), 7200)
        layer.msg('登录成功', {
          icon: 1,
          time: 1500
        }, function () {
          $("[name='username']").val('')
          $("[name='password']").val('')
          var url = localStorage.getItem('url')
          if (url) {
            localStorage.removeItem('url')
            location.href = url
            return false
          }
          location.href = 'shop-list.html'
        })
      } else {
        layer.msg('登录失败', {
          icon: 2,
          time: 1500
        })
      }
    },
    error(xhr, err, msg) {
      console.log('登录失败');
    },
    dataType: 'json',
  })


  return false
})

